<link rel="stylesheet" href="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.css">
<script src="<%- Virtual_Path.Static %>jquery.plugin/pagination/pagination.js"></script>
<script src="<%- Virtual_Path.Static %>jquery.plugin/birthday/birthday.js"></script>
<div class="pay-records-w">
    <div class="x-header-top">
        <div class="header-inner">
            <h2 class="tit">充值记录</h2>
            <div class="ctrl-funs">
                <select class="selected select-year" id="J_SelectYear">
                </select>
                年
                <select class="select-month" id="J_SelectMonth">
                </select>
                月
                <a href="javascript:;" class="query-btn" id="J_SelectQuery">查询</a>
            </div>
        </div>
    </div>
    <div class="main-container">
        <div class="table-info">
            <table class="tab-info">
                <thead>
                <tr>
                    <th>交易号</th>
                    <th>交易时间</th>
                    <th>充值金币</th>
                    <th>支付金额</th>
                    <th>支付方式</th>
                    <th>交易状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="J_OrderList">
                </tbody>
            </table>
        </div>
        <div id="AjaxPagination" class="pagination"></div>
    </div>
</div>

<script>
    $(function(){
        if (!_StateData.IsLogin) {
            $.KOC.Tips.Open('Error', '请先登录', {Timeout: 1000});
            location.href = '/';
        }
        var Create_Date='';
        var _ThisPage = {
            PageParm: {
                P_Get: true,
                Loading: false, //加载中
                Total: null,       //总条数
                MaxCode: "",    //MaxCode
                Start: 0,       //开始
                Length: 4      //页长度
            }
        };
        //时间搜索插件
        $.ms_DatePicker({
            YearSelector: "#J_SelectYear",
            MonthSelector: "#J_SelectMonth"
        });

        //查询
        $('#J_SelectQuery').on('click',function () {
            _ThisPage = {
                PageParm: {
                    P_Get: true,
                    Loading: false, //加载中
                    Total: null,       //总条数
                    MaxCode: "",    //MaxCode
                    Start: 0,       //开始
                    Length: 6      //页长度
                }
            };
            var param={};
            param.year=$.trim($('#J_SelectYear').val());
            param.month=$.trim($('#J_SelectMonth').val());
            Create_Date=param.year+'-'+param.month;
            InitDataList();
        });

        if(Create_Date == ''){
            InitDataList();
        }

        //请求总数
        function InitDataList(){
         $.ajax({
            url: '/ajax/user.order-pay.page',
            type: 'post',
            dataType: 'json',
            data: {
                P_Get: _ThisPage.PageParm.P_Get,
                P_Total: _ThisPage.PageParm.Total,
                P_MaxCode: _ThisPage.PageParm.MaxCode,
                iDisplayStart: _ThisPage.PageParm.Start,
                iDisplayLength: _ThisPage.PageParm.Length,
                Sort_Col:"Create_Date",
                Sort_Dir: "DESC",
                Create_Date:Create_Date
            },
            success: function (data) {
                _ThisPage.PageParm.Loading = false;
                _ThisPage.PageParm.P_Get = false;
                if (data.flag !== 0) {
                    $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                    return;
                }
                _ThisPage.PageParm.Total = data.iTotalRecords;
                var _html = '';
                if(data.iTotalRecords>0){
                    $("#AjaxPagination").empty().pagination(data.iTotalRecords, {
                        num_edge_entries: 2, //边缘页数
                        num_display_entries: 5, //主体页数
                        callback: PageCallback,
                        items_per_page: _ThisPage.PageParm.Length, //每页显示项
                        prev_text: "前一页",
                        next_text: "后一页"
                    });
                }else{
                    var _html = RenderPage(null,data.iTotalRecords);
                    $("#AjaxPagination").empty();
                }
                $('#J_OrderList').empty().html(_html);
            }
        });
        }

        function PageCallback(id) {
            _ThisPage.PageParm.Start =id * _ThisPage.PageParm.Length;
            InitTable();
        }

        function  InitTable() {
            $.ajax({
                url: '/ajax/user.order-pay.page',
                type: 'post',
                dataType: 'json',
                data: {
                    P_Get: _ThisPage.PageParm.P_Get,
                    P_Total: _ThisPage.PageParm.Total,
                    P_MaxCode: _ThisPage.PageParm.MaxCode,
                    iDisplayStart: _ThisPage.PageParm.Start,
                    iDisplayLength: _ThisPage.PageParm.Length,
                    Sort_Col:"Create_Date",
                    Sort_Dir: "DESC",
                    Create_Date:Create_Date
                },
                success: function (data) {
                    _ThisPage.PageParm.Loading = false;
                    _ThisPage.PageParm.P_Get = false;
                    if (data.flag !== 0) {
                        $.KOC.Tips.Open("Error", data.msg + "(" + data.flag + ")", {Timeout: 3000});
                        return;
                    }
                    _ThisPage.PageParm.Total = data.iTotalRecords;
                    _ThisPage.PageParm.MaxCode = data.sMaxCode;
                    _ThisPage.PageParm.Start += _ThisPage.PageParm.Length;
                    var _html = '';
                    if(data.iTotalRecords>0){
                        _.forEach(data.aaData, function (ThisValue) {
                            _html += RenderPage(ThisValue,data.iTotalRecords);
                        });
                    }
                    $('#J_OrderList').empty().html(_html);
                }
            });
        }

        function  RenderPage(ThisValue,len) {
            var _html = '';
            var Pay_Type='';
            if(len > 0){
                if(ThisValue.Pay_Type == 22){
                    Pay_Type='支付宝';
                }else if(ThisValue.Pay_Type == 30){
                    Pay_Type='微信支付';
                }else if(ThisValue.Pay_Type == 20){
                    Pay_Type='网上银行';
                }else if(ThisValue.Pay_Type == 12){
                    Pay_Type='手机充值卡';
                }else if(ThisValue.Pay_Type == 0){
                    Pay_Type='汇付宝';
                }else{
                    Pay_Type='其他方式';
                }
                _html +='<tr>' +
                        '<td>'+ThisValue.Order_No+
                        '</td>'+
                        '<td>'+moment(ThisValue.Create_Date).format('YYYY-MM-DD HH:mm:ss')+
                        '</td>'+
                        '<td>'+ThisValue.Pay_Coin+
                        '</td>'+
                        '<td>'+ThisValue.Pay_Money+
                        '</td>'+
                        '<td>'+Pay_Type+
                        '</td>'+
                        '<td>'+'已支付'+
                        '</td>'+
                        '<td class="tr20">'+'交易成功'+
                        '</td>'+
                        '</tr>';
            }else{
                _html +='<tr>' +
                        '<td colspan="7">'+'暂时没有数据！'+
                        '</td>'+
                        '</tr>';
            }
            return _html;
        }
    });

</script>
